<?php
/**
 * Created by JetBrains PhpStorm.
 * User: dung
 * Date: 2/22/14
 * Time: 1:38 PM
 * To change this template use File | Settings | File Templates.
 */
?>
<?php
if(isset($_SESSION["users_id"]) && $_SESSION["group_id"]==1){
    if(isset($_POST["btnAdd"]))
    {
        $name=$_POST['username'];
        $password=MD5($_POST['password']);
        $email=$_POST['email'];
        $group_id=$_POST["group_id"];settype($group_id,"int");
        AddUser($name,$password,$email,$group_id);
        header("location:index.php?p=userlist");
    }
    ?>
    <form id="maincp" name="form1" method="post" action="">
        <h1 class="h1">Add new user</h1>
        <p>Please complete all form below to add a new article.</p>
        <ul class="list2">
            <li><h3>Username</h3></li>
            <li><input class="input" type="text" name="username" id="username" /></li>
            <li><h3>Password</h3></li>
            <li><input class="input" type="password" name="password" id="password" /></li>
            <li><h3>Confirm Password</h3></li>
            <li><input class="input" type="password" name="confirm" id="confirm" /></li>
            <li><h3>EMail</h3></li>
            <li><input class="input" type="email" name="email" id="email" /></li>
            <li>
                <fieldset>
                    <legend><h3>Group</h3></legend>
                    <p>Choose group for this user.</p>
                    <select id="group_id" name="group_id" style="width: 150px">
                        <?php
                        $group=GroupList();
                        while($row_group=mysql_fetch_array($group)){ ?>
                            <option value="<?php echo $row_group['group_user_id']; ?>"><?php echo $row_group['name']; ?></option>
                        <?php } ?>
                    </select>
                </fieldset>
            </li>
            <li><input class="button adduser" type="submit" name="btnAdd" id="btnAdd" value="Add User" /></li>
        </ul>
        <a href="index.php?p=userlist" title="Back to Dashboard">&laquo; Back to Dashboard.</a>
    </form>
<?php
}else{
    header("location:index.php?p=logincp");
}
?>